package com.ludomancy.spaceopera.entities;
import java.awt.Graphics;
import java.awt.Point;
import com.ludomancy.gamelib.Accumulator;
import com.ludomancy.gamelib.ImageAnimation;
import com.ludomancy.spaceopera.Game;
import com.ludomancy.spaceopera.LandWorld;
import com.ludomancy.spaceopera.Player;


public class WormHazard extends Hazard
{	
	private ImageAnimation anim;
	private Accumulator hitter = new Accumulator(Game.forTime(30));

	public WormHazard(Point pos)
	{
		super(pos);
		z = ZMIDDLE;
		anim = ImageAnimation.create("sandworm.png", 10, 13, 5);
		width = (int) proj.screenToWorldX(anim.strip.frameWidth);
		height = (int) proj.screenToWorldY(anim.strip.frameHeight);
		anim.setSequenceBouncingLoop();
		anim.play();
	}
	
	public boolean isConsumed()
	{
		return anim.isOver();
	}
			
	public void paint(Graphics g, int x, int y)
	{
		anim.update();
		anim.paintCurrentFrame(g, x, y);			
	}
	
	public int[] getBitmask(int x, int y, int w, int h)
	{
		return anim.getBitmask(x, y, w, h);
	}
	
	public boolean update()
	{
		return false;
	}
	
	public void onPlayerHit(Player player)
	{
		hitter.update();
		if(hitter.isDone())
		{
			player.hit(1);
			hitter.reset();
		}
	}

	public int getType()
	{
		return LandWorld.HAZARD_WORM;
	}
}
